﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace BAL.Utils
{
    public class clsCartAndFavorite
    {
        public static string getStringID(List<int> data)
        {
            string re = "";
            foreach(int i in data)
            {
                re += "," + i;
            }
            if (re.Length > 0)
            {
                re = re.Substring(1);
            }
            return re;
        }

        public static List<int> getListID(string ProductsID)
        {
            string[] productID = ProductsID.Split(',');
            List<int> data = new List<int>();
            foreach(string id in productID)
            {
                data.Add(Convert.ToInt32(id));
            }
            return data;
        }

        public static List<int> addNewID(List<int> data, int productID)
        {
            if (data.IndexOf(productID) < 0)
            {
                data.Add(productID);
            }
            return data;
        }

        public static List<int> deleteAnID(List<int> data, int productID)
        {
            int indexItem = data.IndexOf(productID);
            if (indexItem >= 0)
            {
                data.RemoveAt(indexItem);
            }
            return data;
        }
    }
}